package com.apes.framework.plugin.condition.model;

import com.apes.framework.jpa.ApesBean;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：条件表阶梯字段明细
 *
 * @author xul
 * @create 2018-11-06 17:10
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ConditionTableStepped.CONST_TABLE_NAME, indexes = {@Index(columnList = "condition_table_id, code", unique = true)})
public class ConditionTableStepped implements ApesBean {
    public static final String CONST_TABLE_NAME = "tech_condition_table_stepped";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "条件表阶梯字段明细")
    @Comment("编号")
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "condition_table_id", referencedColumnName = "id", nullable = false)
    @Comment("条件表")
    private ConditionTable conditionTable;

    @Column(name = "code")
    @Comment("字段代码")
    private int code;

    @Column(name = "name", nullable = false, length = 120)
    @Comment("字段名称")
    private String name;

    @Transient
    public String stepKeyField() {
        return String.format("step%s", code);
    }

    @Transient
    public String stepValueField() {
        return String.format("step%sAmount", code);
    }

}
